<?php
/**
 * 统计
 * @author lzy <1029460965@qq.com>
 */

namespace app\manage\controller;
use app\common\model\China;
use app\common\model\Engin;
use app\common\model\Order;
use app\common\model\User;
use app\common\model\Team;
use app\common\model\User_account;
class Counts extends Common
{
    /**
     *统计列表
     *@return [type] [description]
     */
    public function lists(){
        return view('',['title'=>'统计']);
    }

    /**
     * 统计用户地理分布
     * @return [type] [description]
     */
    public function counts_user_by_city(){
        $userModel = new User();
        $chinaModel = new China();
        $city = $chinaModel->getList();
        $city_name_arr = [];
        $city = endoceArr($city);

        foreach ($city as $k=>&$vo) {
            $city_name_arr[] = $vo['name'];
            $vo = $vo['id'];
        }

        $data = $userModel->counts_user_by_city('pid',$city);
        //$data = array_combine($city_name_arr,$data);
        $data = array_values($data);
        $res = [
            'city_name'=>$city_name_arr,
            'data'=>$data
        ];
        exit(json_encode($res));

    }

    /**
     * 统计订单数量
     * @return [type] [description]
     */
    public function counts_order(){
        $oModel = new Order();
        $eModel = new Engin();
        $where = ['isexamine'=>1];
        $onum = $oModel->counts($where);//产品订单
        $enum = $eModel->where([])->count();//项目订单
        $data = [
            'odata' => ['value'=>$onum,'name'=>'产品订单'],//在校
            'edata' => ['value'=>$enum,'name'=>'工程订单']//毕业
        ];
        exit(json_encode($data));
    }

    /**
     * 用户身份数量统计
     * @return [type] [description]
     */
    public function counts_user_by_type(){
        $userModel =model('relation');
        $type = config('PLACE');
        //合伙人
        $cper_one = $type['PLACE_CPER_ONE']['id'];//个人合伙人
        $cper_agen = $type['PLACE_AGEN']['id'];//个人合伙人
        $cper_num = $userModel->where(['auth'=>1,'rid'=>['in',[$cper_one,$cper_agen]]])->count();

        //资源人
        $rman_open = $type['PLACE_RMAN_OPEN']['id'];
        $rman_ays = $type['PLACE_RMAN_AYS']['id'];
        $rman_num = $userModel->where(['auth'=>1,'rid'=>['in',[$rman_open,$rman_ays]]])->count();

        //工程师
        $abd_eng = $type['PLACE_ABD_ENG']['id'];
        $abd_eng_num = $userModel->where(['auth'=>1,'rid'=>$abd_eng])->count();

        //技术人员
        $abd_thy = $type['PLACE_ABD_THY']['id'];
        $abd_thy_num = $userModel->where(['auth'=>1,'rid'=>$abd_thy])->count();
        //维保人员
        $mtes = $type['PLACE_MTES']['id'];
        $mtes_num = $userModel->where(['auth'=>1,'rid'=>$mtes])->count();

        $data = [
            'cper_num' => ['value'=>$cper_num,'name'=>'合伙人'],//合伙人
            'rman_num' => ['value'=>$rman_num,'name'=>'资源人'],//资源人
            'abd_eng_num' => ['value'=>$abd_eng_num,'name'=>'工程师'],//工程师
            'abd_thy_num' => ['value'=>$abd_thy_num,'name'=>'技术人员'],//技术人员
            'mtes_num' => ['value'=>$mtes_num,'name'=>'维保人员'],//维保人员
        ];

        exit(json_encode($data));


    }


    /**
     * 资金流水
     * @return html
     */
    public function flow()
    {
        $where = $pageParam = array();
        $keyword = input('get.keyword','');
        if ($keyword) {
            $where['oid'] = array('eq', $keyword);
            $pageParam['query']['keyword'] = $keyword;
        }

        $model = new User_account;
        $data = $model->record($where, $pageParam);

        return view('', [
            'title'     => '资金流水',
            'keyword'   => $keyword,
            'data'      => $data
        ]);
    }







}
